﻿/*
notie : Is not IE
isie  : Is IE
is    : Equal to                  ==
not   : Not equal to              !=
lte   : Less than or equal to     <=
lt    : Less than                 <
gte   : Greater than or equal to  >=
gt    : Greater than              >
*/
// NTKO 附件对象
var NTKO_AttachInfo = new Array(); // 保存服务器上的控件列表信息
var NTKO_AttachObj = new Array();  // NTKO 控件对象

function ieVer(c, i) {
    var v = navigator.appVersion.replace(/(.*)MSIE /, '').replace(/\;(.*)/, '');
    if (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4) {
        if (c == 'isie') {
            return true;
        }
        if (c == 'is') {
            return (v == i);
        }
        if (c == 'not') {
            return (v != i);
        }
        if (c == 'lte') {
            return (v <= i);
        }
        if (c == 'lt') {
            return (v < i);
        }
        if (c == 'gte') {
            return (v >= i);
        }
        if (c == 'gt') {
            return (v > i);
        }
    } else {
        if (c == 'notie') {
            return true;
        }
    }
    return false;
}

/*
功能：计算两个日期的天数差，结束日期减去开始日期
参数：
*/
function DateDiff(startDate, endDate) { //sDate1和sDate2是2002-12-18格式
    var aDate, oDate1, oDate2, iDays;
    aDate = startDate.split("-");
    if (aDate.length != 3) return 0;
    oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]);  //转换为12-18-2002格式
    aDate = endDate.split("-");
    if (aDate.length != 3) return 0;
    oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]);
    iDays = parseInt((oDate2 - oDate1) / 1000 / 60 / 60 / 24);  //把相差的毫秒数转换为天数
    return iDays;
}

// 获取字符串字节长度
String.prototype.getBytesLength = function () {
    return this.replace(/[^\x00-\xff]/gi, "--").length;
};

// 验证是否电话号码
String.prototype.isPhone = function () {
    return (this.search(/^0{0,1}(13[1-9]{1}|15[0,3,8,9]|189)[0-9]{8}$/) != -1 || this.search(/^[0-9]{7,11}$/) != -1);
}

// 验证是否是整数
String.prototype.isInteger = function () {
    return this.search("^-?\\d+$") != -1;
}


// 图片等比缩放
var imageZoom = function (obj, width, height) {
    // 图片小于缩放大小，不进行缩放
    if (obj.width < width && obj.height < height) return;

    var objWidth, objHeight;
    objWidth = obj.width;
    objHeight = obj.height;

    var zoomValue;
    // 获取最大比例做为缩放比例
    zoomValue = objWidth / width > objHeight / height ? objWidth / width : objHeight / height;

    obj.width = objWidth / zoomValue;
    obj.height = objHeight / zoomValue;
}

//// 修复 IE 下 PNG 图片不能透明显示的问题
//function loadImage(myImage) {
//    var arVersion = navigator.appVersion.split("MSIE");
//    var version = parseFloat(arVersion[1]);
//    // 获取浏览器版本号， IE 6.0 版本
//    if ((version >= 5.5) && (version < 7) && (document.body.filters)) {
//        var imgID = (myImage.id) ? "id='" + myImage.id + "' " : "";
//        var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : "";
//        var imgTitle = (myImage.title) ? "title='" + myImage.title + "' " : "title='" + myImage.alt + "' ";
//        var imgStyle = "display:inline-block;" + myImage.style.cssText;
//        var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + myImage.width;
//        strNewHTML += "px; height:" + myImage.height;
//        strNewHTML += "px;" + imgStyle + ";"
//        strNewHTML += "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader";
//        strNewHTML += "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>";

//        myImage.outerHTML = strNewHTML;
//    }
//}


// 获取URL参数的值
function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null)
        return unescape(r[2]);
    return null;
}

// 根据 URL 参数，自动提交流程，Add By HuangJie 2012-4-17
$(function () {
    var parmAction = getQueryString("ParmAction");

    if (parmAction == "Submit") {
        var submits = $("#divTopBars a:contains('提交')");
        if (submits.length == 0)
            submits = $("#divTopBars a:contains('通过')");
        if (submits.length == 0)
            submits = $("#divTopBars a:contains('已阅')");
        if (submits.length > 0) {
            var submitId = submits[0].id;
            __doPostBack(submitId, "");
        }
    }
    else if (parmAction == "Return") {
        var returns = $("#divTopBars a:contains('驳回')");
        if (returns.length == 0)
            returns = $("#divTopBars a:contains('退回')");
        if (returns.length > 0) {
            var returnId = returns[0].id;
            __doPostBack(returnId, "");
        }
    }
});

$(function () {
    // 修复透明背景图片在 IE6 下显示阴影问题
    //    $("img").each(function (index) {
    //        if (this.src.indexOf("http") > -1) {
    //            loadImage(this);
    //        }
    //    });
    // END

    // Add By HuangJie 控制工具栏随滚动条滚动 2010-10-13
    $("input[class='toolbar']").each(function (obj) {
        var obj = $("input[class='toolbar']")[obj];
        var divTopBars = $(obj.parentNode);
        var divBlackArea = divTopBars.next();
        if (obj.value == "1") {// 置于顶端
            // 设置空白区域显示，防止工具栏盖住流程名称
            if (divBlackArea.html() == "") divBlackArea.show();

            divTopBars.css("position", "absolute")
                          .css("width", divTopBars.parent().width());
            divTopBars.parent().resize(function () { divTopBars.css("width", divTopBars.parent().width()); });
            // 设置 Windows 滚动事件
            $(window).scroll(function () {
                divTopBars.css("top", $(document).scrollTop());
            });
        }
        else {
            // 设置空白区域隐藏
            if (divBlackArea.html() == "") divBlackArea.hide();
        }
    });

    // 兼容IE6的样式,Modify By ChenYong
    fixPng();
    $(".divButton").each(function () {
        if ($(this).find("select").length > 0) return;
        var parent = $(this).parent();
        var link = $($(this).find("a:eq(0)"));
        link.remove();

        var linkHTML = $(this).html() + link.html();
        $(this).html(linkHTML);        // 将 Link 内容给 Div
        link.html("");

        $(this).appendTo(link);        // 将 Div 给 Link
        parent.html("");
        link.appendTo(parent);
    });
    // alert(click);
    //               .click(function () {
    //                   $(this).find("a:eq(0)").click();
    //               });
    // END
});

function insertAfter(newElement, targetElement) {
    var parent = targetElement.parentNode;
    if (parent.lastChild == targetElement) {
        parent.appendChild(newElement);
    } else {
        parent.insertBefore(newElement, targetElement.nextSibling);
    }
}

function ShowUnitTips(src) {
    HideUnitTips(src);
    var querierCtrl = $(src);
    var url = querierCtrl.attr("url"); //  src["url"];
    src.id = src["name"];
    var TipID = src.id + "_TipsDiv";
    var TipsDiv = document.getElementById(TipID);
    if (TipsDiv == null) {
        TipsDiv = document.createElement("div");
        TipsDiv.id = TipID;
        TipsDiv.style["border"] = "1px solid #5FC12F";
        TipsDiv.style["backgroundColor"] = "#FFFFFF";
        TipsDiv.style["position"] = "absolute";
        //        TipsDiv.style["marginLeft"] = (-src.offsetWidth) + "px";
        //        if (ieVer('is', 8)) {
        //            TipsDiv.style["marginLeft"] = "0px";
        //        }
        //        TipsDiv.style["marginTop"] = (src.offsetHeight) + "px";
        TipsDiv.style["zIndex"] = "10";
        insertAfter(TipsDiv, src);
        TipsDiv.style["color"] = "black";
    }
    {
        var tipText = document.createElement("span");
        tipText.style["color"] = "red";
        tipText.innerHTML = "数据加载中……";
        TipsDiv.appendChild(tipText);
        var top, left;
        top = parseInt(querierCtrl.offset().top) + parseInt(querierCtrl.height()) + 2;       // 输入框距离上边的位置
        left = querierCtrl.offset().left;                                                    // 输入框距离左边的位置
        $(TipsDiv).css("top", top)
                  .css("left", left);
    }
    TipsDiv.style["display"] = "";

    if (src.value == "") {
        src.parentNode.removeChild(TipsDiv);
        return;
    }

    if (url != null && url.indexOf('?') >= 0) {
        url = url + "&" + Math.random();
    }
    else {
        url = url + "?" + Math.random();
    }
    url = url + "&FindKey=" + encodeURI(src.value) + "&src=" + src.id;

    XmlHttpGetMethodSyn(url, TipsDiv, ShowTipBack);
}

function ShowTipBack(src) {
    var iframeDiv = "<iframe style=\"position: absolute; z-index: -1; filter: alpha(opacity=0);width:0px;height:0px;\"></iframe>";
    if (src.innerHTML.length > 0) {
        src.innerHTML = iframeDiv + src.innerHTML;
    }
    if (src.offsetHeight > 200) {
        src.style["height"] = "200px";
        src.style["paddingRight"] = "16px";
        src.style["overflowY"] = "scroll";
    }
}
function HideUnitTips(src) {
    var TipID = src.id + "_TipsDiv";
    var TipsDiv = document.getElementById(TipID);

    if (TipsDiv != null) {
        src.parentNode.removeChild(TipsDiv);
    }
}

function SelectTipItem(row, nameControlId, idControlId, Text, Value) {
    // IE7: window.opener.document.getElementById(nameControlId).value=Text;
    document.getElementById(nameControlId).value = Text;
    document.getElementById(idControlId).value = Value;
    var div = row.parentElement.parentElement.parentElement;
    div.parentNode.removeChild(div);
    // HideUnitTips(src.parentElement.parentElement.parentElement.parentElement);
    document.getElementById(nameControlId).style.color = "";
}

function KeySelectUnitTip(src) {
    if (event.keyCode == 13) {
        var tipDiv = src.parentNode.lastChild;

        if (tipDiv.tagName != "DIV" ||
            tipDiv.style["display"] == "none" ||
            tipDiv.childNodes.length == 0 ||
            tipDiv.lastChild.tagName != "TABLE") {
            ShowUnitTips(src);
        }
        else {
            for (i = tipTable.rows.length - 1; i >= 0; i--) {
                if (tipTable.rows[i].style['backgroundColor'] == "orange") {
                    tipTable.rows[i].onclick();
                    break;
                }
            }
        }
        event.keyCode = 0;
        event.cancelBubble = true;
        return false;
    }
    return true;
}

/***********************************************************************************************
树形框选人操作 Start
***********************************************************************************************/
//// 展现 TreeView 选人控件
//var setTreeUserShow = function (userNameId, userValueId, unitId) {
//    var obj = $("#" + userNameId);
//    if (selectUserTreeValue == "") {
//        obj.val("请稍候，选人控件正在加载...");
//        return;
//    }
//    selectUserTreeNameId = userNameId;
//    selectUserTreeValueId = userValueId;
//    $("body").unbind("click") 

//    var width, top, left;
//    width = obj.width();                                             // 输入框的宽度
//    top = parseInt(obj.offset().top) + parseInt(obj.height()) + 8;   // 输入框距离上边的位置
//    left = obj.offset().left;                                        // 输入框距离左边的位置

//    if ($("#divUserTree").length == 0) {
//        $("<div></div>")
//        .attr("id", "divUserTree")
//        .appendTo("body");
//    }
//    // 构造用户树形选择控件
//    var divUserTree = $("#divUserTree");
//    var mouseoverColor = "#5FC12F";
//    var mouseoutColor = "#CCCCCC";
//    // 显示控件
//    divUserTree.css("position", "absolute")
//            .css("zIndex", 100)
//            .css("border", "1px solid #5FC12F")
//    // .css("filter", "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=10,finishOpacity=100")
//    // .css("opacity", "0.9")
//            .css("top", top - 4)
//            .css("left", left)
//            .css("backgroundColor", "#FFFFFF")
//            .css("width", width)
//            .css("height", "228px")
//            .css("overflowY", "scroll")
//            .show();

//    var doc = new ActiveXObject("Microsoft.XMLDOM");
//    doc.loadXML(selectUserTreeValue);
//    doc.setProperty("SelectionLanguage", "XPath");
//    var node = doc.selectNodes(".//*[contains(@id,'" + unitId + "')]"); //selectNodes("ul/id[contains(.,'browser')]");
//    if (node.length == 0) return;
//    if (node[0].xml.toString().indexOf("<ul") == 0) {
//        divUserTree.html(node[0].xml);
//    }
//    else {
//        divUserTree.html("<ul id=\"ulUserTree\" class=\"filetree\">" + node[0].xml + "</ul>");
//    }
//    $(divUserTree.find("ul")[0]).attr("class", "filetree");
//    $(divUserTree.find("li")[0]).attr("class", "");
//    if ($("#ulUserTree").length > 0)
//        $("#ulUserTree").treeview();
//    else
//        $("#" + unitId + "").treeview();


//    // 注册关闭方法
//    $("body").click(function (event) {
//        // 判断当前鼠标是否在控件范围内
//        var top = obj.offset().top;
//        var bottom = parseInt(divUserTree.offset().top) + parseInt(divUserTree.height());
//        var left = obj.offset().left;
//        var right = parseInt(obj.offset().left) + parseInt(obj.width());
//        if (event.pageY < top ||
//                event.pageY > bottom ||
//                event.pageX < left ||
//                event.pageX > right) {
//            divUserTree.hide();
//        }
//    });
//}

//var setTreeUserSelected = function (userNameId, userIdsId, selectedText, selectedValue) {
//    document.getElementById(selectUserTreeNameId).value = selectedText;
//    document.getElementById(selectUserTreeValueId).value = selectedValue;
//}


// 展现 TreeView 选人控件
var setTreeUserShow = function (userNameId, userValueId, unitId, treeId) {
    var obj = $("#" + userNameId);
    //$("body").unbind("click");
    var width, top, left;
    width = obj.width();                                             // 输入框的宽度
    top = parseInt(obj.offset().top) + parseInt(obj.height()) + 8;   // 输入框距离上边的位置
    left = obj.offset().left;                                        // 输入框距离左边的位置

    // 构造用户树形选择控件
    var divUserTree = $("#" + treeId + "_TreeView");
    var mouseoverColor = "#5FC12F";
    var mouseoutColor = "#CCCCCC";

    // 显示控件
    divUserTree.css("position", "absolute")
            .css("zIndex", 100)
            .css("border", "1px solid #5FC12F")
    // .css("filter", "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=10,finishOpacity=100")
    // .css("opacity", "0.9")
            .css("top", top - 4)
            .css("left", left)
            .css("backgroundColor", "#FFFFFF")
            .css("width", width)
            .css("height", "228px")
            .css("overflowY", "scroll")
            .show();

    $("#" + treeId + "_" + unitId).treeview();
    // 注册关闭方法
    $("body").click(function (event) {
        // 判断当前鼠标是否在控件范围内
        var top = obj.offset().top;
        var bottom = parseInt(divUserTree.offset().top) + parseInt(divUserTree.height());
        var left = obj.offset().left;
        var right = parseInt(obj.offset().left) + parseInt(obj.width());
        if (event.pageY < top ||
                event.pageY > bottom ||
                event.pageX < left ||
                event.pageX > right) {
            divUserTree.hide();
        }
    });
}

var selectUser = false;

var setTreeUserSelected = function (userNameId, userIdsId, selectedText, selectedValue) {
    document.getElementById(userNameId).value = selectedText;
    document.getElementById(userIdsId).value = selectedValue;
    selectUser = true;
}
/***********************************************************************************************
树形框选人操作 END
***********************************************************************************************/

/***********************************************************************************************
下列框选人操作
***********************************************************************************************/
var currentObj;

// 从组织架构中获取数据，进行下拉框选人列表进行绑定
var setUserListSelect = function (selectUserListUrl, listType, txtUserNames, txtUserIDs, selectType, unitId, roleName, companySelectable, segmentSelectable, orgUnitSelectable, groupSelectable, userSelectable, category, selectMore, unitType, selfUnit) {
    if (selfUnit == null) selfUnit = "0"; // 兼容旧版本
    var isCompanySelectable, isSegmentSelectable, isOrgUnitSelectable, isGroupSelectable, isUserSelectable;
    isCompanySelectable = true; // companySelectable == 1;
    isSegmentSelectable = segmentSelectable == 1;
    isOrgUnitSelectable = orgUnitSelectable == 1;
    isGroupSelectable = groupSelectable == 1;
    isUserSelectable = userSelectable == 1;
    var method = listType;

    $.ajax({
        url: selectUserListUrl,
        data: { UnitID: unitId,
            "ListType": method,
            "UserVisible": isUserSelectable,
            "OUVisible": isOrgUnitSelectable,
            "SegmentVisible": isSegmentSelectable,
            "GroupVisible": isGroupSelectable,
            "RoleName": roleName,
            "CategoryCodes": category,
            "OnlyDisplayOwnUnits": selfUnit
        },
        cache: false,
        async: true,
        type: "POST",
        dataType: "html",
        success: function (data) {
            if (data == null) return;
            if (typeof (data) == "undefined") return;
            try {
                data = eval(data);
                $.setUserListDefault(txtUserNames, txtUserIDs, selectType, data, selectMore, unitType);

            } catch (e) { }
        },
        error: function (e) {
            // alert(e);
        }
    });
}

$.extend({
    lockScreen: function (obj) { // 锁屏
        var msg = "系统正在处理" + obj.innerText + "操作,请稍候。。。";
        var screenObj = new screenClass(msg);
        screenObj.lock();
    },
    unlockScreen: function (obj) { // 解锁
        var screenObj = new screenClass("");
        screenObj.unlock();
    },
    // 用户搜索自动匹配
    autoComplete: function (tableID, value) {
        var table = $("#" + tableID);
        var tr, trs;
        trs = table.find("tr");
        trs.each(function (n) {
            tr = trs[n];
            if (tr.innerText.indexOf(value) > -1) {
                $(tr).show();
            }
            else {
                $(tr).hide();
            }
        })
    },
    // 关闭选择用户框
    closeUserSelect: function () {
        if ($("#divSelectUser").length > 0) {
            $("#divSelectUser").html("");
            $("#divSelectUser").hide();
        }
    },
    // 设置单项项
    setUserSingleSelect: function (userName, userID, id, value) {
        $("#" + userName).val(value);
        $("#" + userID).val(id);
        $.closeUserSelect();
    },
    // 判断数值中是否存在值
    containsValue: function (values, value, splitChar) {
        if ($.trim(values) == "") return false;
        var arr = values.split(splitChar);
        for (var i = 0; i < arr.length; i++) {
            if ($.trim(arr[i]) == $.trim(value)) return true;
        }
        return false;
    },
    // 设置用户多选
    setUserMutiSelect: function (userName, userID, id, value, checked) {
        var names = $.trim($("#" + userName).val());
        var ids = $.trim($("#" + userID).val());
        var arr = ids.split(";");
        if (checked) {// 设置选中
            for (var i = 0; i < arr.length; i++) {
                if (arr[i] == id) {
                    return;
                }
            }
            ids += (ids == "" || ids.substr(ids.length - 1) == ";") ? id : ";" + id;
            names += (names == "" || names.substr(names.length - 1) == ";") ? value : ";" + value;
        }
        else {// 设置非选中
            ids = "";
            var index = 0;
            for (var i = 0; i < arr.length; i++) {
                if (arr[i] == id) { index = i; continue; }
                ids += ids == "" ? arr[i] : ";" + arr[i];
            }
            arr = names.split(";");
            names = "";
            for (var i = 0; i < arr.length; i++) {
                if (i == index) continue;
                names += names == "" ? arr[i] : ";" + arr[i];
            }
        }
        $("#" + userName).val(names);
        $("#" + userID).val(ids);
    },
    /// 设置默认选人
    /*
    userList 数据格式：
    userList = {
    Users : [
    {ID:"ID1",Value:"Name1",Checked:true}
    ,{ID:"ID2",Value:"Name2",Checked:true}
    ,{ID:"ID3",Value:"Name3",Checked:true}
    ]
    }
    }
    
    selectType : 0 表示单选  1 表示多选
    */
    setUserListDefault: function (txtUserNames, txtUserIDs, selectType, userList, selectMore, unitType) {
        var top, left, width;
        obj = $("#" + txtUserNames);
        currentObj = obj;
        width = obj.width();                                            // 输入框的宽度
        top = parseInt(obj.offset().top) + parseInt(obj.height()) + 8;  // 输入框距离上边的位置
        left = obj.offset().left;                                       // 输入框距离左边的位置
        var idValues = $("#" + txtUserIDs).val();                       // 获取已经选定的值
        var html;
        var mouseoverColor = "#5FC12F";
        var mouseoutColor = "#CCCCCC";

        if ($("#divSelectUser").length == 0) {
            $("<div></div>")
                .attr("id", "divSelectUser")
                .css("position", "absolute")
                .css("zIndex", 100)
                .css("border", "1px solid #5FC12F")
                .css("backgroundColor", mouseoutColor)
                .css("filter", "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=10,finishOpacity=100")
                .css("opacity", "0.9")
            //.css("allowtransparency", true)
                .appendTo("body");
        }
        var closeWidth = 63;
        var trValues = "";
        var id, value, checked;
        var selectMode = "";
        if (selectType == 1) {// 多选项
            for (var i = 0; i < userList.Users.length; i++) {
                if (unitType != 8 && unitType != 9 && unitType != 14 && userList.Users[i].Type == "User") continue;  // 可选单位和人时，不显示人
                id = userList.Users[i].ID;
                value = userList.Users[i].Value;
                checked = (idValues.indexOf(userList.Users[i].ID) > -1) ? "checked=\"checked\"" : "";
                trValues += "<tr onmousemove=\"this.bgColor='" + mouseoverColor + "';\" onmouseout=\"this.bgColor='" + mouseoutColor + "';\"><td style=\"font-size:13px\"><input type=\"checkbox\" id=" + id + " " + checked + " onclick=\"$.setUserMutiSelect('" + txtUserNames + "','" + txtUserIDs + "',this.id,'" + value + "',this.checked);\"> " + value + "</td></tr>";
            }
            selectMode = "Multi";
        }
        else {// 单选项
            for (var i = 0; i < userList.Users.length; i++) {
                if (unitType != 8 && unitType != 9 && unitType != 14 && userList.Users[i].Type == "User") continue; // 可选单位和人时，不显示人
                id = userList.Users[i].ID;
                value = userList.Users[i].Value;
                trValues += "<tr onmousemove=\"this.bgColor='" + mouseoverColor + "';\" onmouseout=\"this.bgColor='" + mouseoutColor + "';\" onclick=\"$.setUserSingleSelect('" + txtUserNames + "','" + txtUserIDs + "','" + id + "','" + value + "')\"><td style=\"font-size:13px\"><a style=\"cursor:hand\">" + value + "</a></td></tr>";
            }
            selectMode = "Single";
        }

        var more = "var urlVar = pageInfo.PortalRoot+'/SelectUser.aspx?UserControl=" + txtUserNames + "&UnitType=" + unitType + "&VisibleUnitType=31&VisibleType=3&";
        more += "VisibleUnits=&VisbileCategories=&StartSelectableLevel=0&EndSelectableLevel=100&ExpandToLevel=1&Mode=" + selectMode + "&UserIDControl=" + txtUserIDs + "';";
        more += "var childWindowProperties='toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=510,left=' + (window.screen.width - 600)/2 +',top='+ (window.screen.height - 510)/2; ";
        more += "window.open(urlVar, '', childWindowProperties);"
        var html = "<table style=\"font-size:13px\" border=\"0\" style=\"width:100%\"><tr><td style=\"width:" + (width - closeWidth) + "px;\">";
        html += "搜索：<input type=\"text\" value=\"\" oninput=\"$.autoComplete('tdSelectUser',this.value)\" style=\"width:" + (width - closeWidth - 60) + "px\"></td><td style=\"width:" + closeWidth + "px\">"
        html += "<input type=\"button\" value=\"关闭\" onclick=\"$.closeUserSelect();\"></td></tr>";
        html += "</table>";
        html += "<div style=\"height:210px;overflow-x:hidden;overflow-y:auto;width:100%\">";
        html += "<table id=\"tdSelectUser\" style=\"font-size:13px;width:100%;\" border=\"0\">";
        html += trValues;
        // 需要显示更多
        if (typeof (selectMore) != "undefined" && selectMore == "1") {
            html += "<tr><td style=\"height:26px;\"><a href=\"#\" onclick=\"javascript:" + more + "\">更多...</a></td></tr>";
        }
        html += "<tr><td style=\"height:36px;\">&nbsp;</td></tr>";
        html += "</table>";
        html += "</div>";

        var div = $("#divSelectUser");
        div.html(html)
            .css("top", top - 4)
            .css("left", left)
            .css("width", width)
            .css("height", "228px")
            .css("lang", "")
            .show();

        // 判断当前鼠标是否在控件范围内
        $("body").click(function (event) {
            if (div.length > 0) {
                var top = currentObj.offset().top;
                var bottom = parseInt(div.offset().top) + parseInt(div.height());
                var left = currentObj.offset().left;
                var right = parseInt(currentObj.offset().left) + parseInt(currentObj.width());
                if (event.pageY < top ||
                    event.pageY > bottom ||
                    event.pageX < left ||
                    event.pageX > right) {
                    $("#divSelectUser").html("");
                    $("#divSelectUser").hide();
                }
            }
        });
    }
});

// 检测浏览器是否是 IPad 类型
function isBrowseIPad() {
    var ua = navigator.userAgent.toLowerCase();
    var s;
    s = ua.match(/iPad/i);

    if (s == "ipad") {
        return true;
    }
    else {
        return false;
    }
}
/*
------------------------------------------------------------------
专为茂名石化而做
Create by HuangJie 2011-11-14
Functions:设置没有内容的空行不显示
------------------------------------------------------------------
*/
$(function () {
    $("#tbTable tr").each(function (index) {
        if (index > 2) {
            if ($(this).find("table[id^='tbComment']").length > 0) {
                if ($.trim($(this).find("table[id^='tbComment']").text()) == ""
                    && $(this).find("select").length == 0
                    && $(this).find("td").length == 2
                ) {
                    $(this).hide();
                }
            }
        }
    });

    $("#tbBasicInfo tr").each(function (index) {
        if (index > 2) {
            if ($(this).find("table[id^='tbComment']").length > 0) {
                if ($.trim($(this).find("table[id^='tbComment']").text()) == ""
                    && $(this).find("select").length == 0
                    && $(this).find("td").length == 2
                    ) {
                    $(this).hide();
                }
            }
        }
    });
})
/*
------------------------------------------------------------------
END
------------------------------------------------------------------
*/


function fixPng() {
    var arVersion = navigator.appVersion.split("MSIE");
    var version = parseFloat(arVersion[1]);

    if ((version >= 5.5 && version < 7.0) && (document.body.filters)) {
        for (var i = 0; i < document.images.length; i++) {
            var img = document.images[i];
            var imgName = img.src.toUpperCase();
            if (imgName.indexOf(".PNG") > 0 && (!$(img).is(':hidden'))) {
                var width;
                var height;
                if ($(img).attr("width") != null) {
                    width = $(img).attr("width");
                }
                else {
                    width = img.width;
                }
                if ($(img).attr("height") != null) {
                    height = $(img).attr("height");
                }
                else {
                    height = img.height;
                }
                var sizingMethod = (img.className.toLowerCase().indexOf("scale") >= 0) ? "scale" : "image";
                img.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + img.src.replace('%23', '%2523').replace("'", "%27") + "', sizingMethod='" + sizingMethod + "')";

                var result = "";
                var array = imgName.split('/');
                for (var i = 0; i < array.length - 1; i++) {
                    result += array[i] + "/";
                }
                img.src = result + "blank.gif";
                img.width = width;
                img.height = height;
            }
        }
    }
}

// FUN:获取控件的值，兼容文本框、下拉框、单选框三种类型的控件
// Create By HuangJie 2012-8-30
function getControlValue(id) {
    var ctl = document.getElementById(id);
    if (ctl != null && ctl.type != null) {
        return $(ctl).val();
    }
    if ($("input[name='" + id + "']").length > 0) {
        return $("input[name='" + id + "']:checked").val();
    }
    return "";
}

// 打开主数据选择界面
// Create By HuangJie 2012-8-30
// 参数1：打开的路径
// 参数2：{数据项1:属性,数据项2:属性}，也可以是 {数据项1:属性,控件ClientID:属性}
// 参数3：绑定的业务对象名称
// 参数4：业务对象Load方法的名称
// 参数5：业务对象获取明细方法的名称
// 参数6：绑定的输出参数
// 参数7：业务对象查询的编码
// 参数8: 显示主数据控件的所在容器类型
function openMasterDataWindow(ctrl, url, inputMappings, objectName, listObjectMethod, singleDetailObjectMethod, outputParams, queryCode, containType) {
    var height = 550;
    var width = 700;
    var parm = "";
    var parmValue = "";
    $.each(inputMappings, function (k, v) {
        var id = "";
        $.each(ItemControlMappings, function (item, ctrlId) {
            if (item == k) {
                id = ctrlId;
            }
        });
        if (id == "") id = k;
        parmValue = getControlValue(id);
        if (parmValue != "") {
            parm += parm == "" ? "" : "|";
            parm += v + "," + parmValue;
        }
    });
    // var url = "/Portal/ListMasterData.aspx";
    url += "?ObjectName=" + encodeURI(objectName);
    url += "&ListObjectMethod=" + encodeURI(listObjectMethod);
    url += "&SingleDetailObjectMethod=" + encodeURI(singleDetailObjectMethod);
    url += "&OutputParams=" + encodeURI(outputParams);
    url += "&QueryCode=" + encodeURI(queryCode);
    url += "&ContainType=" + containType;
    url += "&CtrlID=" + ctrl.attr("id");
    if (parm != "") url += "&InputParam=" + encodeURI(parm);
    var childWindowProperties = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=" + width + ",height=" + height + ",";
    childWindowProperties += "left=" + (window.screen.width - width) / 2 + ",top=" + (window.screen.height - height) / 2 + ";";
    popupWindow = window.open(url, "MasterData", childWindowProperties);
    window.popupWindow.focus();
}

// 以下拉框方式显示主数据
function openMasterDataFrame(ctl, url, inputMappings, objectName, listObjectMethod, singleDetailObjectMethod, outputParams, queryCode, containType, height, width) {
    var top, left;
    top = parseInt(ctl.offset().top) + parseInt(ctl.height()) + 4;   // 输入框距离上边的位置
    left = ctl.offset().left;                                        // 输入框距离左边的位置

    var divId = ctl.attr("id") + "_MasterData";
    var div = $("#" + divId);

    // 构造选择主数据的 URL 地址
    var parm = "";
    var parmValue = "";
    $.each(inputMappings, function (k, v) {
        var id = "";
        $.each(ItemControlMappings, function (item, ctrlId) {
            if (item == k) {
                id = ctrlId;
            }
        });
        if (id == "") id = k;
        parmValue = getControlValue(id);
        if (parmValue != "") {
            parm += parm == "" ? "" : "|";
            parm += v + "," + parmValue;
        }
    });
    url += "?ObjectName=" + encodeURI(objectName);
    url += "&ListObjectMethod=" + encodeURI(listObjectMethod);
    url += "&SingleDetailObjectMethod=" + encodeURI(singleDetailObjectMethod);
    url += "&OutputParams=" + encodeURI(outputParams);
    url += "&QueryCode=" + encodeURI(queryCode);
    url += "&ContainType=" + containType;
    url += "&CtrlID=" + ctl.attr("id");
    if (parm != "") url += "&InputParam=" + encodeURI(parm);
    url += "&OpenType=1";
    url += "&Width=" + width;

    if (div.length == 0) {// Div 不存在，则首先创建Div
        $("<div id=\"" + divId + "\" style=\"display:none;\"><iframe id=\"" + ctl.attr("id") + "_frmMasterData\" frameborder=\"0\" height=\"" + height + "\" width=\"" + width + "\" src=\"" + url + "\"></div>").appendTo("body");
    }
    div = $("#" + divId);
    var frame = $("#frmMasterData");
    // 设置位置
    div.css("position", "absolute")
                .css("zIndex", 1)
                .css("lang", "")
                .css("border", "0px solid #5FC12F")
                .css("top", top)
                .css("left", left)
                .css("width", width)
                .css("height", height)
                .show();
    // 注册鼠标移入事件
    div.mouseover(function () {
        div.attr("lang", "1");
    });
    div.mouseout(function (e) {
        if (e.clientY < parseInt(this.style.top)
                    || e.clientY >= parseInt(this.style.top) + parseInt(this.style.height)
                    || e.clientX < parseInt(this.style.left)
                    || e.clientX >= parseInt(this.style.left) + parseInt(this.style.width)
                )
            div.hide();
    });

    ctl.mouseout(function () {
        setTimeout(
                    function () {
                        if (div.attr("lang") == null || div.attr("lang") == "") {
                            div.hide();
                        }
                    }, 500);
    });
}

// FUN:设置控件为只读状态
function setControlReadOnly(itemName) {
    var id;
    if (ItemControlMappings[itemName] != null) {
        id = ItemControlMappings[itemName];
    }
    else id = itemName;
    if ($("#" + id).length > 0) {
        $("#" + id).keydown(function (e) {
            return false;
        });
    }
}

var screenClass = function (msg) {
    /// 解锁
    this.unlock = function () {
        var divLock = document.getElementById("divLock");
        if (divLock != null)
            document.body.removeChild(divLock);

        var frameLock = document.getElementById("frameLock");
        if (frameLock != null)
            document.body.removeChild(frameLock);
    };

    /// 锁屏
    this.lock = function () {
        var sWidth, sHeight, top;
        sWidth = $(document).width();
        sHeight = $(document).height();
        top = $(document).scrollTop() + $(window).height() / 2;
        $("<iframe></iframe>")
                .html("")
                .attr("id", "frameLock")
                .css("position", "absolute")
                .css("top", 0)
                .css("left", 0)
                .css("width", sWidth)
                .css("height", sHeight)
                .css("zIndex", 9)
                .css("backgroundColor", "Transparent")
                .css("frameborder", 0)
                .css("filter", "Alpha(Opacity=0)")
                .css("allowtransparency", true)
                .appendTo("body");
        $("<div></div>")
        //.html("<table id=\"spanLockMessage\" border=\"0\" style=\"width:" + sWidth + "px;font-size:26px;font-weight:bold;position:absolute;top:" + top + "px\"><tr><td align=\"center\">" + msg + "</td></tr></table>")
                .html("<table id=\"spanLockMessage\" border=\"0\" style=\"width:" + sWidth + "px;font-size:26px;font-weight:bold;position:absolute;top:" + top + "px\"><tr><td align=\"center\"><img src=\"" + pageInfo.LockImage + "\"></td></tr></table>")
        //.html("<center><span id=\"spanLockMessage\" style=\"width:"+sWidth+"px;font-size:26px;position:absolute;top:"+top+"px\">"+msg+"</span></center>")
                .attr("id", "divLock")
                .css("position", "absolute")
                .css("top", 0)
                .css("left", 0)
                .css("width", sWidth)
                .css("height", sHeight)
                .css("zIndex", 100)
                .css("backgroundColor", "#CCCCCC")
                .css("filter", "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=55")
                .css("opacity", "0.6")
                .css("allowtransparency", true)
                .appendTo("body");

        $(window).scroll(function () {
            $("#spanLockMessage").css("top", $(document).scrollTop() + $(window).height() / 2);
        });
    };
}